package com.roger.cmdkit.demo;

public class PersonTest {

    public static void main(String[] arg){

        PersonEntity pe = new PersonEntity();
        pe.setName("Hello");
        pe.setAge(-12);
        System.out.println(pe.getName() + pe.getAge());

        try {
            pe = new PersonEntity("Hello",-12);
            System.out.println("name="+ pe.getName()+",age="+ pe.getAge());
        } catch (DataErrorException e) {
            System.out.println("DataErrorException:name or age is illegal,name="+e.getName()+",age="+e.getAge());
        }

        PersonInfo1 pi1 = new PersonInfo1();
        pi1.setName("Hello");
        System.out.println(pi1.name);
        pi1.setName(1,"Hello");
        System.out.println(pi1.name);

        PersonInfo2 pi2= new PersonInfo2();
        System.out.println(pi2.getName());

        PersonInfo3 pi3=new PersonInfo3();
        pi3.setCount(1);
        System.out.println(pi3.count);
        try {
            pi3=new PersonInfo3("",1,2);
            System.out.println(pi3.count);
        } catch (DataErrorException e) {
            e.printStackTrace();
        }
    }


    static class PersonInfo1 extends PersonEntity{
        //Override
        public void setName(String name){ this.name="Override setName()="+name; }
        //Overload
        void setName(int flag,String name){ this.name="Overload setName()="+name+",flag="+flag; }
    }

    static class PersonInfo2 implements PersonInterface {

        @Override
        public String getName() {
            return "Hello,java";
        }

        @Override
        public int getAge() {
            return 0;
        }

    }


    static class PersonInfo3 extends PersonAbstract {
        int count;

        PersonInfo3() {
            super();
            setCount(count);
        }

        PersonInfo3(String name, int age, int count) throws DataErrorException {
            super(name, age);
            setCount(count);
        }

        void setCount(int count) { this.count = count; }
    }

}
